package com.allwees.bs.module.fms.req;

import com.allwees.bs.core.modelbase.branch.EBranchType;
import com.allwees.bs.core.modelbase.exception.AuthException;
import com.allwees.bs.core.modelbase.exception.AuthExceptionEnum;
import com.allwees.bs.core.modelbase.req.BoCrudReq;
import com.allwees.bs.core.modelbase.validate.ValidateItem;
import com.allwees.bs.module.core.constant.EWithdrawAccountChannel;
import com.allwees.bs.module.fms.entity.MerchantWithdrawAccount;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

/**
 * 商户提现账户信息
 *
 * @author yangylsky
 * @since 2019-12-12
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class MerchantWithdrawAccountInfoReq extends BoCrudReq<MerchantWithdrawAccount> {
	private String mobile;

	private String verifyCode;

	@Override
	public ValidateItem[] getValidateItems() {
			return new ValidateItem[] {
				new ValidateItem(bo == null, "bo cannot be a null"),
				new ValidateItem(bo.getChannel().equals(EWithdrawAccountChannel.BANK_CARD) && StringUtils.isBlank(bo.getName()), "【姓名/公司名称】不能为空"),
				new ValidateItem(bo.getChannel().equals(EWithdrawAccountChannel.BANK_CARD) && StringUtils.isBlank(bo.getIdNo()), "【身份证号/组织机构代码】不能为空")
			};
	}

	@Override
	protected void completion() {
		super.completion();

		_updateBranchInfo();
	}

	/**
	 * 根据当前用户不同BranchInfo类型更新对应info
	 *
	 */
	private void _updateBranchInfo() {
		EBranchType branchType = getBranchType();
		getBo().setBranchType(branchType);
		switch(branchType) {
			case SUPPLIER:
				getBo().setBranchUuid(getCurrentSupplierUuid());
				break;
			case RETAILER:
				getBo().setBranchUuid(getCurrentRetailerUuid());
				break;
			default:
				throw new AuthException(AuthExceptionEnum.WRONG_BRANCH_TYPE);
		}
	}
}
